package com.virtium.vpc.action.controller;

import java.util.List;

import com.virtium.vpc.dao.DAOFactory;
import com.virtium.vpc.dao.VpcProductDAO;

import com.virtium.vpc.hibernate.model.VpcProduct;

public class VpcProductManager {
	
	public static boolean addNew(VpcProduct product) {
		try {
			VpcProductDAO vpcProductDAO = DAOFactory.getInstance()
					.getVpcProductDAO();
			return vpcProductDAO.save(product);
		} catch (Exception ex) {
			System.out.println("Error - VpcProductManager - addNew: "
					+ ex.getMessage());
		}
		return false;
	}
	
	public static void delete(String productID){
		try {
			VpcProductDAO vpcProductDAO = DAOFactory.getInstance()
					.getVpcProductDAO();
			VpcProduct product = vpcProductDAO.findById(Integer.parseInt(productID));
			vpcProductDAO.delete(product);
		} catch (Exception ex) {
			System.out.println("Error - VpcProductManager - delete: "
					+ ex.getMessage());
		}
	}
	
	public static List queryString(String query){
		try{
			VpcProductDAO vpcProductDAO = DAOFactory.getInstance()
			.getVpcProductDAO();
			return vpcProductDAO.queryString(query);
		}catch(Exception ex){}
		return null;
	}
	
	public static VpcProduct getProductByID(int id){
		try{
			VpcProductDAO vpcProductDAO = DAOFactory.getInstance()
			.getVpcProductDAO();
			return vpcProductDAO.findById(id);			
		}catch(Exception ex){}
		return null;
	}
	
	public static boolean updateProduct(VpcProduct object){
		try{
			VpcProductDAO vpcProductDAO = DAOFactory.getInstance()
			.getVpcProductDAO();
			return vpcProductDAO.update(object);			
		}catch(Exception ex){}
		return false;
	}
}
